<template>
  <div>
    <FixedOperation>
      <!-- 内容 -->
      <el-row :gutter="20">
        <!--产品分类-->
        <el-col :span="24" :xs="24">
          <div class="text-right">
            <el-button
              :disabled="formData.createBy !== userStore.userInfo.userName"
              type="primary"
              @click="handleUpdate"
              >编辑</el-button
            >
            <el-button
              :disabled="formData.createBy !== userStore.userInfo.userName"
              plain
              type="primary"
              @click="handleDelete"
              >删除</el-button
            >
            <!-- <el-button icon="Refresh" @click="handleReset(form)"
              >重置</el-button
            > -->
          </div>
        </el-col>
      </el-row>
    </FixedOperation>
    <div class="app-container">
      <el-row :gutter="20">
        <el-col :span="24" class="m-b-6">
          <el-descriptions :column="1" :size="'small'" border>
            <el-descriptions-item label="客户姓名" label-class-name="w-1/6">{{
              formData.customerName
            }}</el-descriptions-item>
            <el-descriptions-item label="所属公司">
              <dict-drop
                :options="companyOption"
                :value="formData.deptId"
                :props="{
                  value: 'id',
                  label: 'label'
                }"
              ></dict-drop>
            </el-descriptions-item>
            <el-descriptions-item label="数据来源">
              <dict-drop
                :options="knowledge_source"
                :value="formData.source"
              ></dict-drop>
            </el-descriptions-item>
            <el-descriptions-item label="来电号码">{{
              formData.phone
            }}</el-descriptions-item>
          </el-descriptions>
        </el-col>
      </el-row>
    </div>
  </div>
</template>
<script setup name="ContinuingEducationDetails">
import { useRouter, useRoute } from 'vue-router'
import useCommonStore from '@/store/modules/common'
import useUserStore from '@/store/modules/user'
import {
  getContinuingEducationDetail,
  delContinuingEducation
} from '@/api/customerManage/trainCustomer'
import {
  companyOption //所属公司
} from '@/hooks/dict/order'
import useTagsViewStore from '@/store/modules/tagsView'

const userStore = useUserStore()
const router = useRouter()
const route = useRoute()
const commonStore = useCommonStore()
const { proxy, type } = getCurrentInstance()
const companyData = ref([])
commonStore.getCompanyData().then(e => {
  companyData.value = e
})

const {
  problem_site,
  knowledge_source,
  knowledge_business_type,
  knowledge_type
} = proxy.useDict(
  'problem_site', //问题发生地
  'knowledge_source', //知识库来源
  'knowledge_business_type', //知识库业务类型
  'knowledge_type' //知识库所属分类
)

const props = defineProps({
  knowledgeData: {
    type: Object,
    require: true,
    default: null
  }
})

const data = reactive({
  formData: { fileList: [] },
  formRules: {
    source: [
      {
        required: true,
        message: '请输入数据来源',
        trigger: ['blur', 'change']
      }
    ],
    businessType: [
      {
        required: true,
        message: '请输入业务类型',
        trigger: ['blur', 'change']
      }
    ],
    type: [
      {
        required: true,
        message: '请输入所属分类',
        trigger: ['blur', 'change']
      }
    ],
    content: [
      {
        required: true,
        message: '请输入业务内容',
        trigger: ['blur', 'change']
      }
    ],
    site: [
      {
        required: true,
        message: '请输入问题发生地',
        trigger: ['blur', 'change']
      }
    ]
  },
  dialogParam: {}
})
const { formData, formRules, dialogParam } = toRefs(data)

watch(
  () => route.query.continuingEducationId,
  () => {
    if (route.query.continuingEducationId && route.name == type.name) {
      getFormData(route.query.continuingEducationId)
    }
  },
  {
    immediate: true
  }
)
// 初始化
function init() {}
/** 获取产品详情
 * @param {number}  id 表单id
 */
function getFormData(id) {
  return new Promise((resolve, reject) => {
    getContinuingEducationDetail(id).then(async res => {
      let resData = {}
      resData = res.data
      formData.value = { ...formData.value, ...resData }
      resolve(res)
    })
  })
}

function goTo(url, data) {
  router.push({ path: url, query: data })
}
/**修改按钮操作 */
function handleUpdate(row) {
  goTo('/rsgl/other/knowledgeForm', {
    continuingEducationId: formData.value.id
  })
}
/** 删除按钮操作 */
function handleDelete(row) {
  const continuingEducationIds = formData.value.id
  proxy.$modal
    .confirm('是否删除')
    .then(function () {
      return delContinuingEducation(continuingEducationIds)
    })
    .then(() => {
      proxy.$modal.msgSuccess('删除成功')
      handleReturn()
    })
    .catch(() => {})
}
// 返回、关闭页面
function handleReturn() {
  useTagsViewStore().delView(router.currentRoute.value)
  router.go(-1)
  // router.push({ path: url, query: data })
  //   proxy.$refs.form.clearValidate()
}
init()
</script>
<style scoped></style>
